
package com.huizhan.web.controller;
 
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import io.swagger.annotations.*;
import javax.persistence.*;
import java.util.*;

import com.huizhan.web.dao.*;
import com.huizhan.web.model.*;

/**
 * 内容类型api
 */
 
@Api(tags = "ProjectContentType",description = "内容类型")
@RestController
public class ProjectContentTypeController {
    
    @Autowired
    private ProjectContentTypeDao dao;
   
    /**
     * 获取内容类型集合
     * @return api结果
     */
    @ApiOperation(value = "获取内容类型集合")
    @RequestMapping(value =  "/api/ProjectContentType/",method = {RequestMethod.GET})
    public ApiResult<List<ProjectContentType>> Get(){
         ApiResult<List<ProjectContentType>> result=new ApiResult<List<ProjectContentType>>();
        try 
        {
            List<ProjectContentType> res = dao.findAll();
            result.setData(res);
        }catch(Exception e){
            result.setHasError(true);
            result.setMessage(e.getMessage());
        }
        return  result;
    }

    /**
     * 根据项目ID获取项目内容类型集合
     * @param id 项目ID
     * @return 项目内容类型集合
     */
    @ApiOperation(value = "根据项目ID获取项目内容类型集合")
    @RequestMapping(value =  "/api/ProjectContentType/Project/{projectId}",method = {RequestMethod.GET})
    public ApiResult<List< ProjectContentType>> Project(@PathVariable String projectId){
        ApiResult<List<ProjectContentType>> result=new ApiResult<List<ProjectContentType>>();
        try
        {
            List<ProjectContentType> model= dao.findByProjectId(projectId);
            result.setData(model);
        }catch(Exception e){
            result.setHasError(true);
            result.setMessage(e.getMessage());
        }
        return  result;
    }

    /**
     * 根据ID获取内容类型信息
     * @param id 内容类型ID
     * @return api结果
     */
    @ApiOperation(value = "根据ID获取内容类型信息")
    @RequestMapping(value =  "/api/ProjectContentType/{id}",method = {RequestMethod.GET})
    public ApiResult<ProjectContentType> Get(@PathVariable Long id){
        ApiResult<ProjectContentType> result=new ApiResult<ProjectContentType>();
        try
        {
            ProjectContentType model= dao.getOne(id);
            result.setData(model);
        }catch(Exception e){
            result.setHasError(true);
            result.setMessage(e.getMessage());
        }
        return  result;
    }

    /**
     * 修改内容类型信息
     * @param id 内容类型ID
     * @param model 内容类型信息
     * @return api结果
     */
    @ApiOperation(value = "修改内容类型信息")
    @RequestMapping(value =  "/api/ProjectContentType/{id}",method = {RequestMethod.PUT})
    public ApiResult<ProjectContentType> Edit(@PathVariable Long id,@RequestBody ProjectContentType model){
        ApiResult<ProjectContentType> result=new ApiResult<ProjectContentType>();
        try
        {
            model.setProjectContentTypeId(id);
            dao.save(model);
            result.setData(model);
        }catch(Exception e){
            result.setHasError(true);
            result.setMessage(e.getMessage());
        }
        return  result;
    }

    /**
     * 添加内容类型信息
     * @param model 内容类型信息
     * @return api结果
     */
    @ApiOperation(value = "添加内容类型信息")
    @RequestMapping(value =  "/api/ProjectContentType/",method = {RequestMethod.POST})
    public ApiResult<ProjectContentType> Add(@RequestBody ProjectContentType model){
         ApiResult<ProjectContentType> result=new ApiResult<ProjectContentType>();
        try
        {
            model.setCreateDate(new Date());
            dao.save(model);
            result.setData(model);
        }catch(Exception e){
            result.setHasError(true);
            result.setMessage(e.getMessage());
        }
        return result;
    }
    
    /**
     * 删除内容类型信息
     * @param id 内容类型ID
     * @return api结果
     */
    @ApiOperation(value = "删除内容类型信息")
    @RequestMapping(value =  "/api/ProjectContentType/{id}",method = {RequestMethod.DELETE})
    public ApiResult<Object> Delete(@PathVariable  Long id){
        ApiResult<Object> result=new ApiResult<Object>();
        try 
        {
            dao.deleteById(id);
        }catch(Exception e){
            result.setHasError(true);
            result.setMessage(e.getMessage());
        }
        return result;
    }
}

